<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

use Think\Model;

class ServicePayInit
{
    public $login = true; //是否需要登录才能访问该接口
    public $title = "物业费缴纳初始化信息ok";
    public $group = '物业缴费';
    public $desc = "";

    public $input = [
        'id' => 'required;int;label=租赁合同id;',
    ];

    public $output = [
        [
            'house_id' => 'label=房间id;',
            'building_id' => 'label=楼栋id;',
            'building_name' => 'label=楼栋号;',
            'house_name' => 'label=房间号;',
            'end_time' => 'label=房租过期时间;',
            'expire_days' => 'label=逾期天数;',
            'service_price' => 'label=物业费(元/月);',
        ]
    ];

    public function run($param, $uid)
    {

        $list = M('house_contract')->where(['id' => $param['id']])->find();
        if(!$list) throw new \Exception('未找到该合同');
        $current_time = strtotime(date('Y-m-d'));
        $sum_times = $current_time - strtotime($list['service_end_time']);
        if($sum_times>0){
            $list['expire_days'] = $sum_times/86400;
        }else{
            $list['expire_days'] = 0;
        }
        $building = M('building')->where(['id' => $list['building_id']])->find();
        $house = M('house')->where(['id' => $list['house_id']])->find();
        $list['building_name'] = $building['name'];
        $list['house_name'] = $house['name'];
        return $list;
    }
}
